﻿using System;

using Kugar.Core.ExtMethod;
using Kugar.MVC.MobileUI.WeUI.Enum;
using Kugar.MVC.MobileUI.WeUI.PageControls.PageCommons;

namespace Kugar.MVC.MobileUI.WeUI.Helpers
{
    internal class Utility
    {
        public static string ButtonStyleToStr(ButtonStyleType type)
        {
            switch (type)
            {
                case ButtonStyleType.Default:
                    {
                        return "weui-btn_default";
                    }
                case ButtonStyleType.Primary:
                    {
                        return "weui-btn_primary";
                    }
                case ButtonStyleType.Success:
                    {
                        return "weui-btn_success";
                    }
                case ButtonStyleType.Info:
                    {
                        return "weui-btn_info";
                    }
                case ButtonStyleType.Warning:
                    {
                        return "weui-btn_warn";
                    }
                case ButtonStyleType.Danger:
                    {
                        return "weui-btn_danger";
                    }
                case ButtonStyleType.Link:
                    {
                        return "weui-btn_link";
                    }
                case ButtonStyleType.Lazur:
                {
                    return "weui-btn_lazur";
                }
            }

            return "";
        }

        public static string ButtonConfigToHtml(ButtonItemBase config,string tag="button")
        {
            var href = "href=";

            if (config.getType== ButtonTypeEnum.Link)
            {
                href += $"\"{string.IsNullOrWhiteSpace(config._href).If(config._href, "javascript:;")}\"";
            }

            return
                $"<{tag} {(config.getType== ButtonTypeEnum.Link).If(href)} href=\"javascript:;\" class=\"{Utility.ButtonStyleToStr(config.getButtonStyle)}\" {(config.getOnClickScript.IsNotNullOrEmpty() ? $"onclick =\"{config.getOnClickScript}\"" : "")} id=\"{config.getID}\" type=\"{Utility.ButtonTypeToStr(config.getType)}\">{config.getText}</{tag}>";
        }

        //public static string ButtonSizeToStr(ButtonSize size)
        //{
        //    switch (size)
        //    {
        //        case ButtonSize.Block:
        //            {
        //                return "btn-lg btn-block";
        //            }
        //        case ButtonSize.Default:
        //            {
        //                return "";
        //            }
        //        case ButtonSize.Small:
        //            {
        //                return "btn-sm";
        //            }
        //        case ButtonSize.ExtraSmall:
        //            {
        //                return "btn-xs";
        //            }
        //        case ButtonSize.Large:
        //            {
        //                return "btn-lg";
        //            }

        //    }

        //    return "";
        //}

        public static string ButtonTypeToStr(ButtonTypeEnum type)
        {
            if (type== ButtonTypeEnum.Button)
            {
                return "button";
            }
            else if (type == ButtonTypeEnum.Submit)
            {
                return "submit";
            }

            return "link";
        }

        public static string LinkTargetToStr(LinkTargetType type)
        {
            switch (type)
            {
                case LinkTargetType.Self:
                    return "_self";
                case LinkTargetType.Blank:
                    return "_blank";
                case LinkTargetType.Parent:
                    return "_parent";
                case LinkTargetType.Top:
                    return "_top";
                case LinkTargetType.FrameName:
                    return "";
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }

        public static string FormEncTypeToStr(FormEnctype type)
        {
            switch (type)
            {
                case FormEnctype.Application_urlencoded:
                    return "application/x-www-form-urlencoded";
                    break;
                case FormEnctype.multipart:
                    return "multipart/form-data";
                    break;
                case FormEnctype.plain_text:
                    return "text/plain";
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
    }
}
